﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TopSpace.Bll;

namespace ReturnDB.Taobao.WebApp
{
    public partial class OAuth : System.Web.UI.Page
    {
        protected void Page_Load( object sender , EventArgs e )
        {
            if ( Request.QueryString["top_appkey"] != null )
            {
                //关于回调地址：http://open.taobao.com/dev/index.php/%E8%8E%B7%E5%8F%96SessionKey
                //关于用户验证：http://open.taobao.com/dev/index.php/%E7%94%A8%E6%88%B7%E9%AA%8C%E8%AF%81

                //验证回调地址参数是否合法，如果合法并保存用户数据至Cookie
                if ( Sys.VerifyTopResponse( Request.QueryString["top_parameters"] , Request.QueryString["top_session"] , Request.QueryString["top_sign"] , Config.Appkey , Config.Secret ) == true )
                {
                    //验证成功

                    //从top_parameters为解析当前回调地址登录的nick
                    string nick=new Parser().GetParameters( Request.QueryString["top_parameters"].ToString() , "visitor_nick" );

                    Client.SetCookies( nick , Request.QueryString["top_session"].ToString() );

                    Response.Write( "验证成功！" );
                    Response.Redirect( "Index.aspx" );
                }
                else
                {
                    //验证失败
                    Response.Write( "无效验证！" );
                }
            }
            else
            {
                Response.Write( "无效参数对象，登录验证失败" );
            }
        }
    }
}